package com.sunkyc.framework.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunkyc.framework.system.entity.SysUserRole;
import com.sunkyc.framework.system.mapper.SysUserRoleMapper;
import com.sunkyc.framework.system.service.SysUserRoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户和角色关联表 服务实现类
 * </p>
 *
 * @author sunkyc
 * @since 2022-05-31
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    private final SysUserRoleMapper baseMapper;



    @Override
    public List<SysUserRole> queryRolesByUserId(Long userId) {
        return  baseMapper.selectList(Wrappers.lambdaQuery(SysUserRole.class).eq(SysUserRole::getUserId,userId));
    }

    @Override
    public List<Long> queryRoleIdsByUserId(Long userId) {
        List<Long> longs = queryRolesByUserId(userId).stream().map(item -> item.getRoleId()).collect(Collectors.toList());
        return longs;
    }
}
